from functools import wraps
from flask import g, redirect, url_for


def login_required(func):
    @wraps(func)
    def wrapper(*args, **kwargs):
        if hasattr(g, 'user') and g.user:
            return func(*args, **kwargs)
        else:  # 未登录
            return redirect("/login")

    return wrapper
